﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Biblioteca.Objetos;
using Pms.Utils;
using Biblioteca.Utils;

namespace SERIX
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["op"] != null && Request["op"] == "Sair")
            {
                Session["usuario"] = null;
                Session.Clear();
            }
            //Login1.UserName = "adm";
            //LoginTesteAdm();   
            //Adicionado por Vinicius Cruz dia: 27/06/2011
            
        }

        private void LoginTesteAdm()
        {
            Usuario usu = BiblioPMS.Pesquisar(Login1.UserName.ToUpper(), "LOGIN", "ADM", Criptografia.HashMD5("123456"));
            Session.Add("usuario", usu);
            if (Session["destino"] != null)
            {
                Login1.DestinationPageUrl = Session["destino"].ToString();
                Session["destino"] = null;
            }
            else
            {
                Response.Redirect("~/Logged1.aspx");
            }
        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            Usuario usu = BiblioPMS.Pesquisar(Login1.UserName.ToUpper(), "LOGIN", Login1.UserName.ToUpper(), Criptografia.HashMD5(Login1.Password));
            if (usu != null && !String.IsNullOrEmpty(usu.Nome))
            {
                if (BiblioPMS.AutenticarAcesso(usu.Login))
                {
                    Session.Add("usuario", usu);
                    e.Authenticated = true;
                    if (Session["destino"] != null)
                    {
                        Login1.DestinationPageUrl = Session["destino"].ToString();
                        Session["destino"] = null;
                    }
                    //Adicionado por Vinicius Cruz dia: 27/06/2011
                    Session.Add("popup", "true");
                }
            }
        }

       
    }
}
